package com.summary.richtext.service.impl;

import com.summary.richtext.entity.Student;
import com.summary.richtext.mapper.StudentData;
import com.summary.richtext.service.StudentService;
import com.summary.richtext.utils.ExportRichExcel;
import com.summary.richtext.utils.ImportRichExcel;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Service("StudentService")
public class StudentServiceImpl implements StudentService {


    /**
     * 实现导出
     * @param response
     */
    @Override
    public void realizationExcel(HttpServletResponse response) throws Exception {
        //调取导出数据
        List<Student> dataList = StudentData.getDataList();
        ExportRichExcel exportRichExcel = new ExportRichExcel("学生信息表.xlsx",0,"学生信息表");
        exportRichExcel.setDataList(Student.class, dataList);
        exportRichExcel.increment(1,"老师信息表").setDataList(Student.class, dataList);
        exportRichExcel.write(response).dispose();
    }

    /**
     * 实现导入
     * @param file
     * @return
     */
    @Override
    public List<Student> realizationImprot(MultipartFile file) throws Exception {
        ImportRichExcel sheet1 = new ImportRichExcel(file,1,0);
        List<Student> dataList = sheet1.getDataList(Student.class);
        return dataList;
    }


}
